package com.higgins.lawapp.server.dataModel;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;
import com.higgins.lawapp.client.settings.dataModel.DataSourceObjectDTO;

@PersistenceCapable
public class DataSourceObject {
	@SuppressWarnings("unused")
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	@Persistent
	private String dataSourceType;

	@Persistent
	private String start;

	@Persistent
	private String end;

	@Persistent
	private String label;
	
	@Persistent
	private String fieldName;
	
	@Persistent
	private Integer number;

	@Persistent
	private Boolean url;

	@Persistent
	private Boolean concat;

	public void setDataSourceType(String dataSourceType)	{
		this.dataSourceType = dataSourceType;
	}
	public String getDataSourceType()	{
		return dataSourceType;
	}
	public void setDataSourceStart(String start)	{
		this.start = start;
	}
	public String getDataSourceStart()	{
		return start;
	}
	public void setDataSourceEnd(String end)	{
		this.end = end;
	}
	public String getDataSourceEnd()	{
		return end;
	}
	public void setDataSourceLabel(String label)	{
		this.label = label;
	}
	public String getDataSourceLabel()	{
		return label;
	}
	public void setDataSourceFieldName(String fieldName)	{
		this.fieldName = fieldName;
	}
	public String getDataSourceFieldName()	{
		return this.fieldName;
	}
	public void setDataSourceNumber(Integer number)	{
		this.number = number;
	}
	public Integer getDataSourceNumber()	{
		return number;
	}
	public void setURL(Boolean url)	{
		this.url = url;
	}
	public Boolean getURL()	{
		return url;
	}
	public void setConcat(Boolean concat)	{
		this.concat = concat;
	}
	public Boolean getConcat()	{
		return concat;
	}
	public DataSourceObjectDTO  getDataSourceObjectDTO()	{	
		DataSourceObjectDTO dataSourceObjectDTO = new DataSourceObjectDTO();
		dataSourceObjectDTO = updateDataSourceObjectDTO(dataSourceObjectDTO);
		return dataSourceObjectDTO;
	}
	public DataSourceObjectDTO updateDataSourceObjectDTO(DataSourceObjectDTO dataSourceObjectDTO)	{
		if (dataSourceType.equals("Label"))	{
			dataSourceObjectDTO.setLabel(label);
			dataSourceObjectDTO.setNumber(number);
			dataSourceObjectDTO.setDataSourceType("Label");
		}
		if (dataSourceType.equals("Element"))	{
			dataSourceObjectDTO.setStart(start);
			dataSourceObjectDTO.setEnd(end);
			dataSourceObjectDTO.setDataSourceType("Element");
		}
		if (dataSourceType.equals("Field"))	{
			dataSourceObjectDTO.setStart(start);
			dataSourceObjectDTO.setEnd(end);
			dataSourceObjectDTO.setFieldName(fieldName);
			dataSourceObjectDTO.setURL(url);
			dataSourceObjectDTO.setDataSourceType("Field");
			dataSourceObjectDTO.setConcat(concat);
		}			
		return dataSourceObjectDTO;
	}
	public void updateDataSourceObject(DataSourceObjectDTO dataSourceObjectDTO)	{
		
		if (dataSourceObjectDTO.getDataSourceType().equals("Label"))	{
			setDataSourceType("Label");
			setDataSourceStart(dataSourceObjectDTO.getStart()); 	// ALTER TESE
			setDataSourceEnd(dataSourceObjectDTO.getEnd());		// ALTER THESE
			setDataSourceLabel(dataSourceObjectDTO.getLabel());
			setDataSourceNumber(dataSourceObjectDTO.getNumber());
		}
		if (dataSourceObjectDTO.getDataSourceType().equals("Element"))	{
			setDataSourceType("Element");
			setDataSourceStart(dataSourceObjectDTO.getStart());
			setDataSourceEnd(dataSourceObjectDTO.getEnd());
		}
		if (dataSourceObjectDTO.getDataSourceType().equals("Field"))	{
			setDataSourceType("Field");
			setDataSourceStart(dataSourceObjectDTO.getStart());
			setDataSourceEnd(dataSourceObjectDTO.getEnd());
			setDataSourceFieldName(dataSourceObjectDTO.getFieldName());
			setURL(dataSourceObjectDTO.getURL());
			setConcat(dataSourceObjectDTO.getConcat());
		}		
	}
}
